var ctx;
var firstLevel = 1;
var secondLevel = 2;
var province = '';
var city = '';
var district = '';

function setCtx(ctx) {
	this.ctx = ctx;
}

//验证小区名
function checkCellName(){
	var cellName = $("#cellid").val();
	if(cellName == null || cellName == ""){
		layer.tips('请选择小区名!', '#cellid', {
			tips: 3,
		    time:1000
		});
		return false;
	}else{
		return true;
	}
}

//验证标题
function checkTitle(){
	var title = $("#title").val();
	//解决ie9以下placeholder与value重复的问题
	if(title == $("#title").attr("placeholder")){
		title = "";
	}
	if(title == null || title == ""){
		layer.tips('标题不能为空!', '#title', {
		    tips: 3,
		    time:1000
		});
		return false;
	}else{
		return true;
	}
}

//验证排序不能为空
function checkSort(){
	var reg = /^[0-9]*[1-9][0-9]*$/;
	var sort = $("#sort").val();
	if(sort == null || sort == ""){
		layer.tips('排序不能为空!', '#sort', {
			tips: 3,
			time:1000
		});
		return false;
	}else if(!reg.test(sort)){
		layer.tips('请输入正整数!', '#sort', {
			tips: 3,
			time:1000
		});
		return false;
	}else{
		return true;
	}
}

//保存或新增方法
function saveCellManual() {
	var cellmanualId = $("#cellmanualId").val();
	var title = $("#title").val();
	var subtitle = $("#subtitle").val();
	var keyword = $("#keyword").val();
	var content =ue.getContent();
	var account = $("#account").val();
	var memo = $("#memo").val();
	var cellid = $("#cellid").val();
	var sort = $("#sort").val();
	var imageLogoUrl = $('#imageLogoUrl').val();

    if(checkCellName()&&checkTitle()&&checkSort()){
    	var index1 = layer.load(1);
				$.ajax({
					type : "POST",
					url : ctx + "/cellManual/saveOrUpdateCellManual",
					cache : false,
					dataType : 'json',
					data: {
						title:title,
						subtitle:subtitle,
						keyword:keyword,
						content:content,
						account:account,
						id:cellmanualId,
						cellid:cellid,
						memo:memo,
						sort:sort,
						logo : imageLogoUrl
					},
					success : function(result) {
						if (result.success) {
							layer.msg("操作成功",{
								icon: 1,
								time: 2000 //2秒关闭（如果不配置，默认是3秒）
							},function(){
								loadContent("/cellManual/cellManualList");
							});
						} else {
							layer.close(index1);
							layer.msg("操作失败",{
								icon: 2
							});
						}
					}
				});
    }
}

//返回上一页
function cancel(){
	loadContent("/cellManual/cellManualList"); 
}